package ATBMS.control;

import ATBMS.ucm.UCController;
import ATBMS.ucm.UCRegisterUser;
import ATBMS.view.useredit.UserEditViewInterface;
import java.awt.event.ActionEvent;
import java.awt.event.WindowListener;
import javax.swing.Action;

/**
 * Register Controller
 */
public class RegisterUserControl {

    private UserEditViewInterface ue;
    private UCController ucRegister;
    private Action actionAdapter;
    private WindowListener windowListener;

    public RegisterUserControl() {
        ucRegister = new UCRegisterUser(this);
        actionAdapter = new javax.swing.AbstractAction() {

            public void actionPerformed(ActionEvent e) {
                if (e.getActionCommand().compareTo("Register") == 0) {
                    ucRegister.run();
                    ue.close();
                    MainApp.getApplication().ShowLogin();
                } else if (e.getActionCommand().compareTo("Cancel") == 0) {
                    ue.close();
                    MainApp.getApplication().ShowLogin();
                }
            }
        };
        windowListener = new java.awt.event.WindowAdapter() {

            @Override
            public void windowClosing(java.awt.event.WindowEvent evt) {
                ue.close();
                MainApp.getApplication().ShowLogin();
            }
        };
    }

    public UserEditViewInterface getUserEditView() {
        return ue;
    }

    /**
     * Return a action listener for register view
     * @return Action
     */
    public Action getAction() {
        return actionAdapter;
    }

    /**
     * Return window listener
     * @return windowListener
     */
    public WindowListener getWindowListener() {
        return windowListener;
    }

    /**
     * Set Login View Interface
     */
    public void setUserEditView(UserEditViewInterface ue) {
        this.ue = ue;
    }
}
